package com.pisces.core;

import com.jfinal.aop.Enhancer;
import org.springframework.context.ApplicationContext;


/**
 * Spring工具
 * 
 * @author David Chen
 *
 */
public class SpringKit {

	private static ApplicationContext ctx;
	
	static void init(ApplicationContext ctx) {
		SpringKit.ctx = ctx;
	}
	
	/**
	 * 获取ApplicationContext
	 * 
	 * @return
	 */
	public static ApplicationContext getApplicationContext() {
		return ctx;
	}
	
	/**
	 * 获取bean
	 * 
	 * @param name
	 * @return
	 */
	public static Object getBean(String name) {
		return Enhancer.enhance(ctx.getBean(name));
		
	}
	
	public static <T> T getBean(Class<T> requiredType) {
		return Enhancer.enhance(ctx.getBean(requiredType));
	}
	
}
